<?php

namespace App\Library\OperationLog;

use Closure;

class OperationLogQuery
{

    /**
     * @param string $title
     * @param string $className
     * @param Closure $whereClosure
     * @param $operationLogGroup
     */
    public static function del(
        string $title,
        string $className,
        Closure $whereClosure,
        &$operationLogGroup
    ) {
        $operationLogGroup = $operationLogGroup ?? [];

        array_push($operationLogGroup, new OperationLog(
            OperationLog::TYPE_DEL,
            $title,
            $className::query()->where($whereClosure)->get(),
            null,
            $className::getTranslateConfig()
        ));

        $className::query()->where($whereClosure)->update([
            "updatedAt" => time(),
            "updatedByUid" => request()->user()->id,
            "isDeleted" => 1
        ]);
    }


    /**
     * @param string $title
     * @param string $className
     * @param array $insert
     * @param $operationLogGroup
     */
    public static function insert(
        string $title,
        string $className,
        array $insert,
        &$operationLogGroup
    ) {
        $className::query()->insert($insert);

        array_push($operationLogGroup, new OperationLog(
            OperationLog::TYPE_INSERT,
            $title,
            null,
            $insert,
            $className::getTranslateConfig()
        ));
    }
}
